package cn.ljn.basic.dto;

import cn.ljn.basic.util.MD5Utils;
import cn.ljn.basic.util.StrUtils;
import cn.ljn.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class EmailDto {
    @NotBlank(message = "邮件不能为空")
    private String email;
    @NotBlank(message = "密码不能为空")
    private String password;
    @NotBlank(message = "二次密码不能为空")
    private String passwordRepeat;
    // 注册图形验证码 redis key
    @NotBlank(message = "uuid不能为空")
    private String imageCodeKey;
    // 注册图形验证码
    @NotBlank(message = "图形验证码不能为空")
    private String imageCodeValue;

    public User getUser(){
        // 获取盐值
        String randomString = StrUtils.getComplexRandomString(32);
        // MD5密码加密
        String password = MD5Utils.encrypByMd5(randomString + this.password);

        return User.builder()
                .username(this.email)
                .email(this.email)
                .createtime(new Date())
                .password(password)
                .salt(randomString)
                .state(1)
                .build();
    }
}
